(function($){ 
	
    var methods =
    {
    	init : function (){
    		var self = this;
    		var buffer = [];
    		buffer.push("<div class='umselect'>");
    		buffer.push('<input type="hidden" data-id="'+$(self).attr("id")+'"/>');
    		buffer.push('<input type="text" readonly="true" class="umselect_inp" validate="required"/>');
    		buffer.push('<div class="umselect_content"></div>');
    		buffer.push("</div>");
    		$(self).html(buffer.join(""));
   		
    		$(self).find("[class=umselect_content]").delegate('li:not([class="noactive"])' ,"click" ,function (){
    			$(self).find("[class=umselect_content]").hide();
    			if ($(this).attr("data-id"))
    			{
        			$(self).find("[class=umselect_inp]").val($(this).html());
        			$('[data-id='+$(self).attr("id")+']').val($(this).attr("data-id"));
        			if ($(self).data("options").itemClick)
        			{
        				$(self).data("options").itemClick($(this).attr("data-id"));
        			}
        			
    			}
    			else
    			{
        			$(self).find("[class=umselect_inp]").val("");
        			$('[data-id='+$(self).attr("id")+']').val("");
    			}
    			return false;
    		});
    		
    		$(self).find("[class*=umselect_inp]").click(function (e){
    			$(self).find("[class=umselect_content]").show();
    			e.stopPropagation();//阻止冒泡到body
    		});
    		
    		$("body").click(function(){
    			$(self).find("[class=umselect_content]").hide();
    		});

    		$(self).find("[class=umselect_content]").click(function(e){
				e.stopPropagation();//阻止冒泡到body
			});
    	},
    	value : function(){
    		return $(this).find('[data-id='+$(this).attr("id")+']').val();
    	},
    	setName :function(id){
    		var str = $(this).find('li[data-id="'+id+'"]').html();
    		$(this).find("[class=umselect_inp]").val(str);
    	},
    	setContent : function(htmlStr){
    		$(this).find("[class=umselect_content]").html(htmlStr);
    	}
    };
	
	$.fn.umSelect = function(options){
        if (methods[options]) {
            return methods[options].apply(this, Array.prototype.slice.call(arguments, 1));
        }
		var defaults ={};
		var options = $.extend(defaults, options);
		this.each(function()
		{
			$(this).data("options" ,options);
			methods["init"].apply(this);
		});
	};
})(jQuery);